﻿
Partial Class UCMain_summary_report
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If IsNothing(Session("section")) Then
            Session.Clear()
            Response.Redirect("../Login.aspx")
        End If
        If Not IsPostBack Then
            loaddata()
        End If

    End Sub

    Sub loaddata()
        Dim sql1 As String
        Dim starttime As DateTime
        Dim endtime As DateTime
        If txtDateStart.Text = "" Then
            starttime = New DateTime(1950, 1, 1)
        Else
            Dim dates() As String = txtDateStart.Text.Split("/")
            starttime = New DateTime(dates(2), dates(1), dates(0))
        End If
        If txtDateEnd.Text = "" Then
            endtime = DateTime.Now
        Else
            Dim dates() As String = txtDateEnd.Text.Split("/")
            endtime = New DateTime(dates(2), dates(1), dates(0))
        End If
        Dim dt As New Data.DataTable
        Dim where As String = " AND CDate(DUR_WORK_FORM) >= CDate('" & starttime.AddYears(-543).ToString("yyyy/MM/dd") & "') AND CDate(DUR_WORK_TO) <= CDate('" & endtime.AddYears(-543).ToString("yyyy/MM/dd") & "')"
        Try

            sql1 = " select count(T1) as cT1 from [request_table] where STATUS_APP='1' and T1='1' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl1.Text = dt.Rows(0)("cT1")

            sql1 = " select count(T2) as cT2 from [request_table] where STATUS_APP='1' and T2='2' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl2.Text = dt.Rows(0)("cT2")

            sql1 = " select count(T3) as cT3 from [request_table] where STATUS_APP='1' and T3='3' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl3.Text = dt.Rows(0)("cT3")

            sql1 = " select count(T4) as cT4 from [request_table] where STATUS_APP='1' and T4='4' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl4.Text = dt.Rows(0)("cT4")

            sql1 = " select count(T5) as cT5 from [request_table] where STATUS_APP='1' and T5='5' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl5.Text = dt.Rows(0)("cT5")

            sql1 = " select count(T6) as cT6 from [request_table] where STATUS_APP='1' and T6='6' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl6.Text = dt.Rows(0)("cT6")

            sql1 = " select count(T7) as cT7 from [request_table] where STATUS_APP='1' and T7='7' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl7.Text = dt.Rows(0)("cT7")

            sql1 = " select count(T8) as cT8 from [request_table] where STATUS_APP='1' and T8='8' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl8.Text = dt.Rows(0)("cT8")

            sql1 = " select count(T9) as cT9 from [request_table] where STATUS_APP='1' and T9='9' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl9.Text = dt.Rows(0)("cT9")


            sql1 = " select count(V1) as cV1 from [request_table] where STATUS_APP='1' and v1='1' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl10.Text = dt.Rows(0)("cV1")

            sql1 = " select count(V2) as cV2 from [request_table] where STATUS_APP='1' and v2='2' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl11.Text = dt.Rows(0)("cV2")

            sql1 = " select count(V3) as cV3 from [request_table] where STATUS_APP='1' and v3='3' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl12.Text = dt.Rows(0)("cV3")

            sql1 = " select count(V4) as cV4 from [request_table] where STATUS_APP='1' and v4='4' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl13.Text = dt.Rows(0)("cV4")

            sql1 = " select count(V5) as cV5 from [request_table] where STATUS_APP='1' and v5='5' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl14.Text = dt.Rows(0)("cV5")

            sql1 = " select count(V6) as cV6 from [request_table] where STATUS_APP='1' and v6='6' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl15.Text = dt.Rows(0)("cV6")

            sql1 = " select count(V7) as cV7 from [request_table] where STATUS_APP='1' and v7='7' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl16.Text = dt.Rows(0)("cV7")

            'sql1 = " select count(V8) as cV8 from [request_table] where STATUS_APP='1' and v8='8' " & where
            'dt = clsCommand.SQL_exec(sql1)
            'lbl17.Text = dt.Rows(0)("cV8")

            sql1 = " select count(u.[SECTION]) as cVAFC "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='AFC' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl18.Text = dt.Rows(0)("cVAFC")

            sql1 = " select count(u.[SECTION]) as cBES "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='BES' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl19.Text = dt.Rows(0)("cBES")

            sql1 = " select count(u.[SECTION]) as cCIV "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='CIV' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl20.Text = dt.Rows(0)("cCIV")

            sql1 = " select count(u.[SECTION]) as cCOM "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='COM' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl21.Text = dt.Rows(0)("cCOM")

            sql1 = " select count(u.[SECTION]) as cPSD "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='PSD' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl22.Text = dt.Rows(0)("cPSD")

            sql1 = " select count(u.[SECTION]) as cPSY "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='PSY' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl23.Text = dt.Rows(0)("cPSY")
            
            sql1 = " select count(u.[SECTION]) as cRST "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='RST' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl24.Text = dt.Rows(0)("cRST")


            sql1 = " select count(u.[SECTION]) as cSIG "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='SIG' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl26.Text = dt.Rows(0)("cSIG")

            sql1 = " select count(u.[SECTION]) as cSTN "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='STN' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl27.Text = dt.Rows(0)("cSTN")

            sql1 = " select count(u.[SECTION]) as cTO "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='TO' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl28.Text = dt.Rows(0)("cTO")

            sql1 = " select count(u.[SECTION]) as cTRW "
            sql1 += " from [request_table]  rq inner join [user_table] u on rq.REQ_ID_PICOP =u.ID_USER"
            sql1 += " where rq.STATUS_APP='1' and u.[SECTION]='TRW' " & where
            dt = clsCommand.SQL_exec(sql1)
            lbl29.Text = dt.Rows(0)("cTRW")

        Catch ex As Exception
            img.Visible = True
            lblerror.Text = Utility.clsAlertMsg.infoMessage(img, "E004", ex.Message.ToString)
        End Try
    End Sub

    Private Function GetDateFormat(strDate As String) As DateTime
        Dim dates() As String = strDate.Split("/")
        Return New DateTime(dates(2), dates(1), dates(0))
    End Function

    Protected Sub Btn_Search_Click(sender As Object, e As EventArgs) Handles Btn_Search.Click
        loaddata()
    End Sub

    
End Class
